function main(source) {
	let result = [];
	const dep = (arr) => {
		for (let i = 0; i < arr.length; i++) {
			let n = arr[i];
			let l = arr[i + 1];
			if (n > l) {
				arr[i] = l;
				arr[i + 1] = n;
			}
		}
		result.push(arr[arr.length - 1]);
		delete arr[arr.length - 1];
		arr = arr.filter((v) => Boolean(v));
		if (arr.length !== 0) {
			dep(arr);
		}
	};
	dep(source);
	result.reverse();
	return result;
}

// console.log(main([3, 1, 5, 4, 6]));

function main2(source) {
	for (let i = 0; i < source.length; i++) {
		for (let j = 0; j < source.length - i; j++) {
			let temp;
			if (source[j] > source[j + 1]) {
				temp = source[j];
				source[j] = source[j + 1];
				source[j + 1] = temp;
			}
		}
	}
}
let arr = [3, 1, 5, 4, 6];
main2(arr);
console.log(arr);
